package com.javatest.springboot2basictest.config;

import com.javatest.springboot2basictest.aop.Aspect;
import com.javatest.springboot2basictest.bean.JuiceMaker;
import com.javatest.springboot2basictest.bean.Source;
import com.javatest.springboot2basictest.processor.BeanPostProcessorImpl;
import com.javatest.springboot2basictest.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2020-04-14 下午12:50
 */
@Slf4j
@EnableAspectJAutoProxy
//@ComponentScan({"com.javatest.springboot2basictest.service","com.javatest.springboot2basictest.aop"})
@Configuration
public class BeanConfig {

    @Bean
    public Source source() {
        return new Source("橙汁", "少糖", "大杯");
    }

    @Bean(initMethod = "init", destroyMethod = "myDestory")
    public JuiceMaker juiceMaker() {
        JuiceMaker juiceMaker = new JuiceMaker();
        log.warn("[JuiceMaker]在@Bean标记的方法中执行属性配置");
        juiceMaker.setBeverageShop("贡茶");
        return juiceMaker;
    }

    /**
     * 在使用@Bean注解构造BeanPostProcessor时，返回值类型一定要是接口实现类或者至少是BeanPostProcessor
     * 因为BeanPostProcessor类型很特殊，容器在启动的初期就要优先进行初始化，因此需要被明确的标识并识别
     *
     * @return
     */
    //@Bean("testBeanPostProcessor")
    public BeanPostProcessor beanPostProcessor() {
        return new BeanPostProcessorImpl();
    }

    @Bean
    public TestService testService() {
        return new TestService();
    }

    @Bean
    public Aspect aspect() {
        return new Aspect();
    }
}
